/*
 * jq4r helper JavaScript functions
 *
 * AUTHOR: Lin-Chieh Shangkuan (ericsk)
 * SINCE: 0.2
 */
(function($){
    
    $.fn.uiOverlay = null;
    $.fn.uiBox = null;
    $.fn.uiCurrentBox = null;
    
    $.fn.uiAddBox = function(elemid) {
        var body = document.body || document.getElementsByTagName('body')[0];
        var ww = body.clientWidth || document.documentElement.clientWidth;
        var wh = body.clientHeight || document.documentElement.clientHeight;
        
        if ($.fn.uiBox == null) {
            $.fn.uiBox = document.createElement('div');
            $.fn.uiBox.id = elemid;
            $.fn.uiBox.className = 'jq-box';
        }
        $('body').append($.fn.uiBox);
        
        var e = $('.jq-box');        
        e.css('left', (ww-e.width())/2 + body.scrollLeft);
        e.css('top', (wh-e.height())/2 + body.scrollTop);
        
        if ($.fn.uiOverlay == null) {
            $.fn.uiOverlay = document.createElement('div');
            $.fn.uiOverlay.className = "jq-overlay";
            $.fn.uiOverlay.style.width = $(document).width() + 'px';
            $.fn.uiOverlay.style.height = $(document).height() + 'px';
        }
        $('body').append($.fn.uiOverlay);
        
        e.fadeIn('normal');
        $.fn.uiCurrentBox = $('.jq-box');
    }
    
    $.fn.uiAdjustBox = function() {
        var body = document.body || document.getElementsByTagName('body')[0];
        if ($('.jq-box')) {
            var e = $('.jq-box');
            
            var ww = body.clientWidth || document.documentElement.clientWidth;
            var wh = body.clientHeight || document.documentElement.clientHeight;

            e.css('left', (ww-e.width())/2 + body.scrollLeft);
            e.css('top', (wh-e.height())/2 + body.scrollTop);
        }
    }
    
    $.fn.uiRemoveBox = function() {
        if ($.fn.uiCurrentBox) {
            $.fn.uiCurrentBox.fadeOut('fast');
            $.fn.uiCurrentBox = null;
        }
        $('.jq-overlay').remove();
    }
    
})(jQuery);